package com.zy.tree;

import com.zy.TreeNode;

/**
 * @description: 二叉树的最大深度
 * @author: zhaoyi
 * @create: 2019-09-08 13:43
 * https://leetcode-cn.com/explore/orignial/card/recursion-i/259/complexity-analysis/1225/
 **/

public class BinaryTreeMaxDeep {

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return seek(root, 1);
    }

    private int seek(TreeNode node, int deep) {
        if (node.left == null && node.right == null) {
            return deep;
        } else if (node.left != null && node.right != null) {
            int left = seek(node.left, deep + 1);
            int right = seek(node.right, deep + 1);
            return Math.max(left, right);
        }else if(node.left == null){
            return seek(node.right, deep + 1);
        }else {
            return seek(node.left, deep + 1);
        }
    }


}


